home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DropFTP / DSUserProcs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  7.3 KB  |  243 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DSUserProcs.c
  5. **
  6. **   Description:    Specific AppleEvent handlers used by the DropBox
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Time    Author    Description
  23. **    --------    -----    ------    ---------------------------------------------
  24. **    01/25/92            LDR        Removed the use of const on the userDataHandle
  25. **    12/09/91            LDR        Added the new SelectFile userProc
  26. **                                Added the new Install & DisposeUserGlobals procs
  27. **                                Modified PostFlight to only autoquit on odoc, not pdoc
  28. **    11/24/91            LDR        Added the userProcs for pdoc handler
  29. **                                Cleaned up the placement of braces
  30. **                                Added the passing of a userDataHandle
  31. **    10/29/91            SCS        Changes for THINK C 5
  32. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  33. **                                Added a bunch of comments for clarification
  34. **    10/06/91    00:02    MTC        Converted to MPW C
  35. **    04/09/91    00:02    LDR        Added to Projector
  36. **
  37. ******************************************************************************/
  38.  
  39.  
  40. #include "DSGlobals.h"
  41. #include "DSUserProcs.h"
  42. #include "string.h"
  43. #include "ftp.h"
  44. #include "pref.h"
  45.  
  46.  
  47.     char     host[256];
  48.     char     user[256];
  49.     char     pswd[256];
  50.     
  51. /*
  52.     This routine is called during init time.
  53.     
  54.     It allows you to install more AEVT Handlers beyond the standard four
  55. */
  56. #pragma segment Main
  57. pascal void InstallOtherEvents (void) {
  58. }
  59.  
  60.  
  61. /*    
  62.     This routine is called when an OAPP event is received.
  63.     
  64.     Currently, all it does is set the gOApped flag, so you know that
  65.     you were called initally with no docs, and therefore you shouldn't 
  66.     quit when done processing any following odocs.
  67. */
  68. #pragma segment Main
  69. pascal void OpenApp (void) {
  70.     gOApped = true;
  71. }
  72.  
  73.  
  74. /*    
  75.     This routine is called when an QUIT event is received.
  76.     
  77.     We simply set the global done flag so that the main event loop can
  78.     gracefully exit.  We DO NOT call ExitToShell for two reasons:
  79.     1) It is a pretty ugly thing to do, but more importantly
  80.     2) The Apple event manager will get REAL upset!
  81. */
  82. #pragma segment Main
  83. pascal void QuitApp (void) {
  84.     gDone = true;    /*    All Done! */
  85. }
  86.  
  87.  
  88. /*    
  89.     This routine is the first one called when an ODOC or PDOC event is received.
  90.     
  91.     In this routine you would place code used to setup structures, etc. 
  92.     which would be used in a 'for all docs' situation (like "Archive all
  93.     dropped files")
  94.  
  95.     Obviously, the opening boolean tells you whether you should be opening
  96.     or printing these files based on the type of event recieved.
  97.     
  98.     userDataHandle is a handle that you can create & use to store your own
  99.     data structs.  This dataHandle will be passed around to the other 
  100.     odoc/pdoc routines so that you can get at your data without using
  101.     globals - just like the new StandardFile.  
  102.     
  103.     We also return a boolean to tell the caller if you support this type
  104.     of event.  By default, our dropboxes don't support the pdoc, so when
  105.     opening is FALSE, we return FALSE to let the caller send back the
  106.     proper error code to the AEManager.
  107.  
  108.     You will probably want to remove the #pragma unused (currently there to fool the compiler!)
  109. */
  110. #pragma segment Main
  111. pascal Boolean PreFlightDocs (Boolean opening, Handle *userDataHandle) {
  112. #pragma unused ( userDataHandle )
  113.  
  114.     return opening;        // we support opening, but not printing - see above
  115. }
  116. void xstrcpy(char *s1,char *s2);
  117. void xstrcpy(char *s1,char *s2)
  118. {
  119.     register char *p2 = s2;
  120.     register char *p1 = s1;
  121.     while (*p2) {
  122.         *p1++ = *p2++;
  123.     }
  124. }
  125. /*    
  126.     This routine is called for each file passed in the ODOC event.
  127.     
  128.     In this routine you would place code for processing each file/folder/disk that
  129.     was dropped on top of you.
  130.     
  131.     You will probably want to remove the #pragma unused (currently there to fool the compiler!)
  132. */
  133. #pragma segment Main
  134. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle ) {
  135.  
  136.  
  137.     char     thefile[256];
  138.     Ptr        data;
  139.     long    filesize;
  140.     short    refNum;
  141.     short oe;
  142.     Handle h;
  143.     
  144. //#pragma unused ( myFSSPtr )
  145. //#pragma unused ( opening )
  146. //#pragma unused ( userDataHandle )
  147.  
  148.     if (FSpOpenDF(myFSSPtr,fsRdPerm,&refNum)== noErr) {
  149.         oe=GetEOF(refNum,&filesize);
  150.         if ((h=NewHandle(filesize)) !=nil) {
  151.             oe=FSRead(refNum,&filesize,*h);
  152.             HLock(h);
  153.             strcpy(thefile,p2cstr((StringPtr)myFSSPtr->name));
  154.             
  155.             FTPPutFile (host, user, pswd, thefile,*h,filesize);
  156.             HUnlock(h);
  157.             DisposeHandle(h);
  158.         }
  159.         oe=FSClose(refNum);
  160.         InitCursor();
  161.     }
  162. }
  163.  
  164.  
  165. /*    
  166.     This routine is the last routine called as part of an ODOC event.
  167.     
  168.     In this routine you would place code to process any structures, etc. 
  169.     that you setup in the PreflightDocs routine.
  170.  
  171.     If you created a userDataHandle in the PreFlightDocs routines, this is
  172.     the place to dispose of it since the Shell will NOT do it for you!
  173.     
  174.     You will probably want to remove the #pragma unusued (currently there to fool the compiler!)
  175. */
  176. #pragma segment Main
  177. pascal void PostFlightDocs ( Boolean opening, Handle userDataHandle ) {
  178. #pragma unused ( opening )
  179. #pragma unused ( userDataHandle )
  180.  
  181.     if ( (opening) && (!gOApped) )
  182.         gDone = true;    //    close everything up!
  183.  
  184.     /*
  185.         The reason we do not auto quit is based on a recommendation in the
  186.         Apple event Registry which specifically states that you should NOT
  187.         quit on a 'pdoc' as the Finder will send you a 'quit' when it is 
  188.         ready for you to do so.
  189.     */
  190. }
  191.  
  192.  
  193. /*
  194.     This routine is called when the user chooses "Select File…" from the
  195.     File Menu.
  196.     
  197.     Currently it simply calls the new StandardGetFile routine to have the
  198.     user select a single file (any type, numTypes = -1) and then calls the
  199.     SendODOCToSelf routine in order to process it.  
  200.             
  201.     The reason we send an odoc to ourselves is two fold: 1) it keeps the code
  202.     cleaner as all file openings go through the same process, and 2) if events
  203.     are ever recordable, the right things happen (this is called Factoring!)
  204.  
  205.     Modification of this routine to only select certain types of files, selection
  206.     of multiple files, and/or handling of folder & disk selection is left 
  207.     as an exercise to the reader.
  208. */
  209. pascal void SelectFile (void)
  210. {
  211.     StandardFileReply    stdReply;
  212.     SFTypeList            theTypeList;
  213.  
  214.     StandardGetFile(NULL, -1, theTypeList, &stdReply);
  215.     if (stdReply.sfGood)    // user did not cancel
  216.         SendODOCToSelf(&stdReply.sfFile);    // so send me an event!
  217. }
  218.  
  219. /*
  220.     This routine is called during the program's initialization and gives you
  221.     a chance to allocate or initialize any of your own globals that your
  222.     dropbox needs.
  223.     
  224.     You return a boolean value which determines if you were successful.
  225.     Returning false will cause DropShell to exit immediately.
  226. */
  227. pascal Boolean InitUserGlobals(void)
  228. {
  229.  
  230.     ReadPref();
  231.     return(true);    // nothing to do, it we must be successful!
  232. }
  233.  
  234. /*
  235.     This routine is called during the program's cleanup and gives you
  236.     a chance to deallocate any of your own globals that you allocated 
  237.     in the above routine.
  238. */
  239. pascal void DisposeUserGlobals(void)
  240. {
  241.     // nothing to do for our sample dropbox
  242. }
  243.